package com.ktjy.ch15.service.impl;

import com.ktjy.ch15.entity.MeetinGroom;
import com.ktjy.ch15.mapper.MeetinGroomMapper;
import com.ktjy.ch15.service.MeetinGroomService;
import com.ktjy.ch15.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("meetinGroomService")
public class MeetinGroomServiceImpl implements MeetinGroomService {

    @Autowired
    private MeetinGroomMapper meetinGroomMapper;

    @Override
    public Page<MeetinGroom> findPage(MeetinGroom meetinGroom, Integer pageNo, Integer pageSize) {
        Page<MeetinGroom> page = new Page<MeetinGroom>();
        page.setPageNo(pageNo);
        page.setPageSize(pageSize);
        // 查询总数，计算总页数
        Integer count = meetinGroomMapper.count(meetinGroom);
        page.setTotalCount(count);
        // 查询分页数据
        Integer pageBegin=(pageNo-1)*pageSize;
        List<MeetinGroom> data = meetinGroomMapper.getPage(meetinGroom, pageBegin, pageSize);
        page.setData(data);
        return page;
    }

    @Override
    public boolean save(MeetinGroom meetinGroom) {
        return meetinGroomMapper.insert(meetinGroom) > 0;
    }

    @Override
    public MeetinGroom findById(Long id) {
        return meetinGroomMapper.getById(id);
    }

    @Override
    public boolean update(MeetinGroom meetinGroom) {
        return meetinGroomMapper.update(meetinGroom) > 0;
    }

    @Override
    public boolean delete(Long id) {
        return meetinGroomMapper.delete(id) > 0;
    }

    @Override
    public MeetinGroom findByName(String name) {
        return meetinGroomMapper.getByName(name);
    }
}
